package com.mycp.mycpcommonlib

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.hjq.permissions.OnPermissionCallback
import com.hjq.permissions.Permission
import com.hjq.permissions.XXPermissions
import com.ifmvo.togetherad.core.listener.InterListener
import com.ifmvo.togetherad.core.listener.RewardListener
import com.thl.filechooser.FileChooserListUtils
import com.xzkj.ad.AdManager

//提交到app
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        ImmersionBar.with(this).init()
        setContentView(R.layout.splash)
        permissions()


//        val initSdk = MdidSdkHelper.InitSdk(
//            this,
//            true,
//            MiitHelper(object : MiitHelper.AppIdsUpdater {
//                override fun OnIdsAvalid(ids: String) {
//                    MyLog.e("设备id"+ids)
//                }
//            }))
//        val helper = OaidHelper(object : AppIdsUpdater() {
//            fun OnIdsAvalid(isSupport: Boolean, oaid: String?, vaid: String?, aaid: String?) {
//                if (!isSupport || TextUtils.isEmpty(oaid)) {
//                    return
//                }
//                SPUtil.putString(Key.KEY_OAID, oaid)
//            }
//        })
//        helper.getDeviceIds(this)
//        AdManager.loadBannerAD(this, container, object :BannerListener{
//            override fun onAdClose(providerType: String) {
//                /*container.postDelayed({
//                    AdManager.loadBannerAD(this@MainActivity, container,this)
//                }, 3000)*/
//            }
//
//            override fun onAdFailed(providerType: String, failedMsg: String?) {
//                /*container.postDelayed({
//                    AdManager.loadBannerAD(this@MainActivity, container,this)
//                }, 3000)*/
//            }
//        })
    }

    private fun permissions() {
        val permissionStrs = listOf(
//            Permission.CAMERA,
            Permission.MANAGE_EXTERNAL_STORAGE,
            Permission.READ_PHONE_STATE
        ).toMutableList()
        XXPermissions.with(this)
            // 不适配 Android 11 可以这样写
            //.permission(Permission.Group.STORAGE)
            // 适配 Android 11 需要这样写，这里无需再写 Permission.Group.STORAGE
            .permission(permissionStrs)
            .request(object : OnPermissionCallback {
                override fun onGranted(permissions: List<String>, all: Boolean) {
                    if (permissions.contains(Permission.MANAGE_EXTERNAL_STORAGE)) {
//                        startForPermission("/storage/emulated/0/Android/data", this@MainActivity)
//                        startActivity(Intent(this@MainActivity,MainActivity2::class.java))
                        FileChooserListUtils.openFileSelect(this@MainActivity,"选择文件",4
                        ) { }
                    }
                }

                override fun onDenied(permissions: List<String>, never: Boolean) {
                    if (never) {
                        // 如果是被永久拒绝就跳转到应用权限系统设置页面
                        XXPermissions.startPermissionActivity(this@MainActivity, permissions)
                    } else {
                    }
                }
            })

    }

    fun rewardAd(view: View) {
        AdManager.loadRewardAD(this, object :RewardListener{
            override fun onAdClose(providerType: String) {

            }

            //拿到激励广告的奖励
            override fun onAdRewardVerify(providerType: String) {

            }
        })
    }

    fun interAd(view: View) {
        AdManager.loadInterAD(this, object :InterListener{
            override fun onAdClose(providerType: String) {

            }
        })
    }

}